@model LanLordz.Models.TournamentDetailsModel
@{
    ViewBag.Title = Model.Tournament.Title + " | View Tournament";
    var controller = this.ViewContext.Controller as LanLordzBaseController;
}
@section headers
{
  <!--[if IE]>
  <script type="text/javascript" src="@Html.LocalContent("~/Scripts/svgcheck.js")"></script>
  <script type="text/vbscript" src="@Html.LocalContent("~/Scripts/svgcheck.vbs")"></script>
  <![endif]-->
}
    <div class="EventsNavigator">@Html.ActionLink(controller.Config.SiteName + " Events", "Index") &gt; @Html.ActionLink(Model.Event.Title, "Details", new { id = Model.Event.EventID }) &gt; @Model.Tournament.Title</div>
    <h2>@Model.Tournament.Title</h2>
    <dl>
     <dt>Team Size:</dt><dd>@Model.Tournament.TeamSize</dd>
     <dt>Game:</dt><dd>@Model.Tournament.Game</dd>
     <dt>Type:</dt><dd>@Model.Tournament.PairingsGenerator</dd>
     @if (!string.IsNullOrEmpty(Model.Tournament.GameInfo))
     {
     <dt>Game Info:</dt><dd>@Html.BBCode(Model.Tournament.GameInfo)</dd>
     }
     @if (!string.IsNullOrEmpty(Model.Tournament.ServerSettings))
     {
     <dt>Server Settings:</dt><dd>@Html.BBCode(Model.Tournament.ServerSettings)</dd>
     }
    </dl>
    @if (Model.UserAccess.CanCreateTeam || Model.UserAccess.CanDisbandTeam || Model.UserAccess.CanInputScores || Model.UserAccess.CanJoinTeam || Model.UserAccess.CanLeaveTeam || Model.UserAccess.CanManageTeam || Model.UserAccess.CanRollBackRound || Model.UserAccess.CanStartNextRound || Model.UserAccess.CanLockTeams || Model.UserAccess.CanUnlockTeams || Model.UserAccess.CanEditTeams)
    {
    <div class="TournamentTools">
        @if (Model.UserAccess.CanCreateTeam)
        {
     <div class="TournamentToolsCreateTeam">@Html.ActionLink(!(Model.Tournament.TeamSize == 1) ? "Create a Team" : "Join Tournament", "CreateTeam", new { id = Model.Tournament.TournamentID })</div>
        }
        @if (Model.UserAccess.CanJoinTeam)
        {
     <div class="TournamentToolsJoinTeam">@Html.ActionLink("Join a Team", "JoinTeam", new { id = Model.Tournament.TournamentID })</div>
        }
        @if (Model.UserAccess.CanLeaveTeam || Model.UserAccess.CanDisbandTeam)
        {
     <div class="TournamentToolsLeaveTeam">@Html.ActionLink(!(Model.Tournament.TeamSize == 1) ? "Leave your Team" : "Leave Tournament", "LeaveTeam", new { id = Model.Tournament.TournamentID })</div>
        }
        @if (Model.UserAccess.CanManageTeam)
        {
     <div class="TournamentToolsManageTeam">@Html.ActionLink("Manage your Team", "ManageTeam", new { id = Model.Tournament.TournamentID })</div>
        }
        @if (Model.UserAccess.CanLockTeams)
        {
     <div class="TournamentToolsLockTeams">@Html.ActionLink("Lock Teams", "LockTeams", new { id = Model.Tournament.TournamentID })</div>
        }
        @if (Model.UserAccess.CanUnlockTeams)
        {
     <div class="TournamentToolsUnlockTeams">@Html.ActionLink("Unlock Teams", "UnlockTeams", new { id = Model.Tournament.TournamentID })</div>
        }
        @if (Model.UserAccess.CanEditTeams)
        {
     <div class="TournamentToolsEditTeams">@Html.ActionLink("Edit Teams", "EditTeams", new { id = Model.Tournament.TournamentID })</div>
        }
        @if (Model.UserAccess.CanInputScores)
        {
     <div class="TournamentToolsInputScores">@Html.ActionLink("Input Scores", "InputScores", new { id = Model.Tournament.TournamentID })</div>
        }
        @if (Model.UserAccess.CanStartNextRound)
        {
     <div class="TournamentToolsStartNextRound">@Html.ActionLink(Model.Rounds.Any() ? "Start Next Round" : "Start Tournament", "StartNextRound", new { id = Model.Tournament.TournamentID })</div>
        }
        @if (Model.UserAccess.CanRollBackRound)
        {
     <div class="TournamentToolsRollBackRound">@Html.ActionLink("Roll-back Tournament", "RollBackRound", new { id = Model.Tournament.TournamentID })</div>
        }
    </div>
    }
    <div class="EventTournamentTeamsList">
     <div class="EventTournamentTeamsListTitle">@(Model.Tournament.TeamSize > 1 ? "Teams" : "Participants")</div>
    @if (!Model.Teams.Any())
    {
     <div class="EventTournamentTeamsNotAvailable">No @(Model.Tournament.TeamSize > 1 ? "teams" : "participants") yet registered.</div>
    }
    @foreach (var Team in Model.Teams)
    {
     <div class="EventTournamentTeam">
      <div class="EventTournamentTeamName">@Team.TeamName</div>
      @if (Model.Tournament.TeamSize > 1)
      {
      <div class="EventTournamentTeamMembers">
          @foreach (var User in Team.UsersTeams.OrderByDescending(u => u.IsTeamCaptain))
          {
       <div class="EventTournamentTeamMemberName@(User.IsTeamCaptain ? "" : " EventTournamentTeamMemberTeamCaptain")">@Html.UserLink(User.User.UserID, User.User.Username, string.Format(Team.TeamTagFormat, User.User.Username))</div>
          }
      </div>
      }
     </div>
    }
    </div>
    <div class="EventTournamentStandings">
     <div class="EventTournamentStandingsTitle">@(Model.TournamentFinished ? "Final" : "Current") Standings</div>
    @if (Model.Standings == null || !Model.Standings.Any())
    {
     <div class="EventTournamentStandingsNotAvailable">Standings are not @(Model.TournamentFinished ? "yet" : "currently") available.</div>
    }
    else
    {
     <table class="EventTournamentStandingsTable">
      <tr class="EventTournamentStandingsTableHeader">
       <th class="EventTournamentStandingsTableHeaderRank">Rank</th>
       <th class="EventTournamentStandingsTableHeaderTeam">Team</th>
       <th class="EventTournamentStandingsTableHeaderDetails">Details</th>
      </tr>
        @foreach (var Standing in Model.Standings)
        {
      <tr class="EventTournamentStandingsTableStanding">
       <td class="EventTournamentStandingsTableStandingRank">@Standing.Rank</td>
       <td class="EventTournamentStandingsTableStandingTeam">@Standing.Team.TeamName</td>
       <td class="EventTournamentStandingsTableStandingDetails">@Standing.Details</td>
      </tr>
        }
     </table>
    }
    </div>
    <div class="EventTournamentRoundsList">
     <div class="EventTournamentRoundsListTitle">Rounds</div>
    @if (!Model.Rounds.Any())
    {
     <div class="EventTournamentRoundsNotAvailable">The tournament has not yet started.</div>
    }
    else
    {
        if (Model.CanRenderView)
        {
     <div class="EventTournamentRoundsListVisualization">
      <!--[if IE]>
      <script language="JavaScript">
       //<![CDATA[
        checkAndGetSVGViewer();
       //]]>
      </script>
      <embed src="@Url.Action("RenderTournament", new { id = Model.Tournament.TournamentID })" type="image/svg+xml"
        width="@Model.RenderedSize.Value.Width" height="@Model.RenderedSize.Value.Height"
        wmode="transparent"
        pluginspage="http://www.adobe.com/svg/viewer/install/" />
      <![endif]-->
      <![if !IE]>
      <object data="@Url.Action("RenderTournament", new { id = Model.Tournament.TournamentID })" type="image/svg+xml"
        width="@Model.RenderedSize.Value.Width" height="@Model.RenderedSize.Value.Height">
      </object>
      <![endif]>
     </div>
        }
        foreach (var Round in Model.Rounds.OrderBy(r => r.RoundNumber))
        {
     <div class="EventTournamentRound">
      <div class="EventTournamentRoundTitle">@("Round " + Round.RoundNumber)</div>
      <div class="EventTournamentRoundPairingsList">
            @foreach (var Pairing in Round.Pairings)
            {
       <div class="EventTournamentRoundPairing">
        <table class="EventTournamentRoundPairingTeamsList">
                @foreach (var TeamPairing in Pairing.TeamsPairings.OrderByDescending(tp => tp.Score))
                {
         <tr class="EventTournamentRoundPairingTeam">
          <td class="EventTournamentRoundPairingTeamName">@TeamPairing.Team.TeamName</td>
          <td class="EventTournamentRoundPairingTeamScore">@(Pairing.TeamsPairings.Count() == 1 ? "Bye" : (string.IsNullOrEmpty(TeamPairing.Score) ? "?" : TeamPairing.Score))</td>
         </tr>
                }
        </table>
       </div>
            }
      </div>
     </div>
        }
    }
    </div>
